/**
 * Created by 徐嘉宾 on 2016/8/16.
 */
$(document).ready(function () {
        $('#w0 tr').each(function () {
            var a = $(this).children('th').text();
            if (a == '一级分类') {
                var b = $(this).children('td');
                $.get("./?r=admin/getclass1", {"id": b.text()}, function (data) {
                    b.html(data);
                });
            }
            if (a == '二级分类') {
                var c = $(this).children('td');
                $.get("./?r=admin/getclass2", {"id": c.text()}, function (data) {
                    c.html(data);
                });
            }
            if (a == '难度') {
                var d = $(this).children('td');
                if (d.text() == '0') {
                    d.html("暂无");
                }
                if (d.text() == '1') {
                    d.html("简单");
                }
                if (d.text() == '2') {
                    d.html("一般");
                }
                if (d.text() == '3') {
                    d.html("高");
                }
            }
        });


        $.get("./?r=admin/getreadtype1", function (data) {
            var a = data.split("/");
            for (var i = 0; i < a.length - 1; i++) {
                var j = a[i].split(" ");
                var k = "<option value='" + j[0] + "'>" + j[1] + "</option>";
                $('#speakingcontent-class1_id').append(k);
            }
        });
        $('#speakingcontent-class1_id').change(function () {
            $("#speakingcontent-class2_id option:not(:contains(' '))").remove();
            var b = $('#speakingcontent-class1_id option:selected').val();
            $.get("./?r=admin/getreadtype2", {id: b}, function (data) {
                var a = data.split("/");
                for (var i = 0; i < a.length - 1; i++) {
                    var j = a[i].split(" ");
                    var k = "<option value='" + j[0] + "'>" + j[1] + "</option>";
                    $('#speakingcontent-class2_id').append(k);
                }
            });
        });
        if(c1!=false&&c2!=false) {
            $.get("./?r=admin/getclass1", {id: c1}, function (data) {
                var e = data;
                $('#speakingcontent-class1_id').append("<option value='" + c1 + "' selected='selected'>" + e + "</option>");
            });
            $.get("./?r=admin/getclass2", {id: c2}, function (data) {
                var f = data;
                $('#speakingcontent-class2_id').append("<option value='" + c2 + "' selected='selected'>" + f + "</option>");
            });
        }
        if (c3 == 'false') {
            $('#speakingcontent-img_url').val('www.test.com/img');
            $('#img').show();
            $('#img').click(function () {
                $('#img').hide();
            });
        } else {
            $('#img1').show();
            $('#img1').click(function () {
                $('#img1').hide();
                $('#imggg').append("<a id='getimg'>点击插入链接</a>");
                $('#getimg').click(function () {
                    $.ajax({
                        url: "./?r=ajax/getspeakimgurl&id="+h,
                        dataType: 'json',
                        type: 'get',
                        success: function (data) {
                            $('#speakingcontent-img_url').val(data);
                            $('#getimg').hide();
                            $('#speakingcontent-img_url').show();
                        }
                    });
                });


            });
        }
    $('#img1').click(function () {
        $('#img1').hide();
        $('#imggg').append("<a id='getimg'>点击插入链接</a>");
        $('#getimg').click(function () {
            $.ajax({
                url: "./?r=ajax/getspeakimgurl&id="+h,
                dataType: 'json',
                type: 'get',
                success: function (data) {
                    $('#speakingcontent-img_url').val(data);
                    $('#getimg').hide();
                    $('#speakingcontent-img_url').show();
                }
            });
        });


    });
    $('#speakingcontent-reading_content').hide();
    var editor = UE.getEditor('editor');
    if (c4!='false'){
        UE.getEditor('editor').ready(function () {
            UE.getEditor('editor').setContent(c4);
        });
    }
    $('.btn-success,.btn-primary').click(function () {
        var g = UE.getEditor('editor').getContent();
        $('#speakingcontent-reading_content').val(g);
    });
    if (c4!='false'){
        $('#speakingcontent-diff option').each(function () {
            var v = $(this).val();
            if (v==c5){
                $(this).attr("selected" ,true);
            }
        });
    }

    $('#speakingcontent-listening_content').hide();
    var editor1 = UE.getEditor('editor1');
    if (c10!='false'){
        UE.getEditor('editor1').ready(function () {
            UE.getEditor('editor1').setContent(c10);
        });
    }
    $('.btn-success,.btn-primary').click(function () {
        var g1 = UE.getEditor('editor1').getContent();
        $('#speakingcontent-listening_content').val(g1);
    });

    if(c6!='false'){
        $('#direction1').show();

        $('#direction1').click(function () {
        $('#direction1').hide();
        });
        }else{
        $('#direction').show();
        $('#speakingcontent-direction').val('www.test.com/img');
        $('#direction').click(function () {
            $('#speakingcontent-direction').show();
            $('#direction1').hide();
        });
    }
    $('#direction1').click(function () {
        $('#direction1').hide();
        $('#directionnn').append("<a id='getdirection'>点击插入链接</a>");
        $('#getdirection').click(function () {
            $.ajax({
                url: "./?r=ajax/getspeakdirection&id="+h,
                dataType: 'json',
                type: 'get',
                success: function (data) {
                    $('#speakingcontent-direction').val(data);
                    $('#getdirection').hide();
                    $('#speakingcontent-direction').show();
                }
            });
        });
    });

    if(c7!='false'){
        $('#topic1').show();
        $('#topic1').click(function () {
            $('#topic1').hide();
        });
    }else{
        $('#topic').show();
        $('#speakingcontent-topic_content').val('www.test.com/img');
        $('#topic').click(function () {
            $('#speakingcontent-topic_content').show();
            $('#topic').hide();
        });
    }

    $('#topic1').click(function () {
        $('#topic1').hide();
        $('#topic_contenttt').append("<a id='gettopiccontent'>点击插入链接</a>");
        $('#gettopiccontent').click(function () {
            $.ajax({
                url: "./?r=ajax/getspeaktopiccontent&id="+h,
                dataType: 'json',
                type: 'get',
                success: function (data) {
                    $('#speakingcontent-topic_content').val(data);
                    $('#gettopiccontent').hide();
                    $('#speakingcontent-topic_content').show();
                }
            });
        });
    });


    if(c8!='false'){
        $('#script1').show();
        $('#script1').click(function () {
            $('#script1').hide();
        });
    }else{
        $('#script').show();
        $('#speakingcontent-listening_script').val('www.test.com/img');
        $('#script').click(function () {
            $('#speakingcontent-listening_script').show();
            $('#script').hide();
        });
    }

    $('#script1').click(function () {
        $('#script1').hide();
        $('#listening_scripttt').append("<a id='getlisteningscript'>点击插入链接</a>");
        $('#getlisteningscript').click(function () {
            $.ajax({
                url: "./?r=ajax/getspeaklistenscript&id="+h,
                dataType: 'json',
                type: 'get',
                success: function (data) {
                    $('#speakingcontent-listening_script').val(data);
                    $('#script1').hide();
                    $('#speakingcontent-listening_script').show();
                }
            });
        });
    });

    if(c9!='false'){
        $('#readtips1').show();
        $('#readtips1').click(function () {
            $('#readtips1').hide();
            $('#reading_tipsss').append("<a id='getreadtips'>点击插入链接</a>");
            $('#getreadtips').click(function () {
                $.ajax({
                    url: "./?r=ajax/getspeakreadtips&id="+h,
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        $('#speakingcontent-reading_tips').val(data);
                        $('#readtips1').hide();
                        $('#speakingcontent-reading_tips').show();
                    }
                });
            });
        });
    }else{
        $('#readtips').show();
        $('#speakingcontent-reading_tips').val('www.test.com/img');
        $('#readtips').click(function () {
            $('#speakingcontent-reading_tips').show();
            $('#readtips').hide();
        });
    }

    $('#readtips1').click(function () {
        $('#readtips1').hide();
        $('#reading_tipsss').append("<a id='getreadtips'>点击插入链接</a>");
        $('#getreadtips').click(function () {
            $.ajax({
                url: "./?r=ajax/getspeakreadtips&id="+h,
                dataType: 'json',
                type: 'get',
                success: function (data) {
                    $('#speakingcontent-reading_tips').val(data);
                    $('#getreadtips').hide();
                    $('#speakingcontent-reading_tips').show();
                }
            });
        });
    });
});
